<template>
  <div id="top_id">
    <el-dropdown>
      <span class="el-dropdown-link">
        <el-avatar icon="el-icon-user-solid"></el-avatar>
        <div id="name">{{names}}</div>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item>个人中心</el-dropdown-item>
        <el-dropdown-item>
          <span @click="del">退出登陆</span>
        </el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  data() {
    return {
      names: ""
    };
  },
  methods: {
    del() {
      localStorage.removeItem("log_list");
      this.$router.push("/login");
    }
  },
  mounted() {
    var name = JSON.parse(localStorage.getItem("log_list"));
    this.names = name.username;
  }
};
</script>

<style>
#top_id .el-avatar {
  display: inline-block;
  margin-top: 10px;
}
#top_id #name {
  display: inline-block;
  vertical-align: top;
  margin-left: 5px;
  color: red;
  font-weight: 900;
}
</style>